Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust js guard behavior #317

Merged
merged 2 commits into from Jul 20, 2019
Merged

adjust js guard behavior #317

merged 2 commits into from Jul 20, 2019

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Jul 20, 2019

This changes the behaviour of the js guard functions (isHook, isTestCase, and isDescribe) to match the TS behaviour in #316

Currently only CallExpressions whose entire member chain is described in the related Set are considered to be "X" (where "X" is a hook, test case, or describe depending on which is<x> method is called).

For example, this means that describe.only.each isn't considered a describe by isDescribe.

This PR changes that behaviour to just the first member in the chain for if they're in the related Set.

Neither behaviour is strictly right or wrong, but this behavioural change currently exists in the TS branch, and so a change has to happen somewhere.

The new behaviour doesn't cause any tests to fail (aside from in no-if, which has been fixed), so it could be merged & released to get a scope on what the impact of this change will be.

'xit',
'xtest',
]);
export const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to export this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to verify, test.only is still detected, yeah?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good point about the export - I'll check it right now.

Definitely still catches test.only, b/c otherwise no-focused-tests would fail :)

All of the places that actually do something specific for things like only & skip actually implement their own checks; which makes sense b/c there's no way to explicitly get them out of the Set.

That's why it all still works, b/c the sets & guards are meant to serve as a way to know if you're in the "jest domain" (and so if you should bother checking anything at all), rather than for explicit "is it this specific jest method".

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests pass with less code - I'm happy 🙂

@SimenB SimenB merged commit 84df1d6 into jest-community:master Jul 20, 2019
@G-Rath G-Rath deleted the adjust-guard-behaviour branch July 20, 2019 09:27
@SimenB
Copy link
Member

SimenB commented Jul 21, 2019

🎉 This PR is included in version 22.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants